package ru.papergames.model.binsocket.packets
{
	import ru.papergames.model.binsocket.data.ExtByteArray;
	
	public class SocketResponse extends BaseSocketPacket
	{
		public static const NOTIFICATION:String = 'SocketResponse.GENERIC_SOCKET_RESPONSE';
		
		public function SocketResponse(bytes:ExtByteArray)
		{
			super();
			bytes.position = 0;
			this.packetID = bytes.readUnsignedByte();
			this.binaryData = new ExtByteArray();
			bytes.readBytes(this.binaryData);
			if (this.binaryData.length > 0) {
				decode();
				
				//if there is more bytes - throw error
				if (this.binaryData.bytesAvailable > 0)
						throw new Error('The packet contains undecoded bytes!');
			}			
		}
		
		protected function decode():void {
			
		}
		
		public function getNotification():String {
			return NOTIFICATION;
		}
		
		override public function toString():String {
			return getNotification() + ":\n" + (binaryData ? binaryData.toString() : 'null') + "\n" + this.dump(); ; 
		} 
				
	}
}